﻿using System;

namespace Glue.Converters
{
    internal abstract class GlueDefaultConverter<T1,T2> : BaseSimpleConverter<T1,T2>
    {
        internal abstract T2 InternalMapTowardsRight(T1 from);
        internal abstract T1 InternalMapTowardsLeft(T2 from);
        
        public sealed override T2 MapTowardsRight(T1 from)
        {
            try
            {
                return InternalMapTowardsRight(from);
            }
            catch
            {
                throw new GlueException(String.Format("The converter '{0}' cannot map the value '{1}' to a {2}-value", GetConverterName(),from,typeof(T2).Name));
            }
        }

        public sealed override T1 MapTowardsLeft(T2 from)
        {
            try
            {
                return InternalMapTowardsLeft(from);
            }
            catch
            {
                throw new GlueException(String.Format("The converter '{0}' cannot map the value '{1}' to a {2}-value", GetConverterName(), from, typeof(T1).Name));
            }
        }
    }
}
